import yaml
from pydantic import BaseModel

class Config(BaseModel):
    database: str
    api_key: str

def load_config() -> Config:
    try:
        with open("config.yml", "r") as file:
            config = yaml.load(file, Loader=yaml.FullLoader)
            return Config(**config)
    except FileNotFoundError:
        print("配置未发现")
    except yaml.YAMLError as e:
        print(f"YAML 解析错误")

config = load_config()

if config:
    print(f"数据库配置: ", {config.database})
    print("api_key", config.api_key)

